package goliath;

import pulpcore.sprite.*;
import pulpcore.image.CoreFont;
import pulpcore.image.Colors;
import pulpcore.animation.event.SceneChangeEvent;
import pulpcore.animation.event.TimelineEvent;
import pulpcore.animation.Timeline;
import pulpcore.scene.Scene2D;
import pulpcore.scene.Scene;
import pulpcore.net.Download;
import pulpcore.Stage;

/**
 * @author will
 * @date Aug 10, 2008 12:49:06 AM
 */
public class DownloadScene extends Scene2D {
    Download download;

    public DownloadScene(Download d) {
        this.download = d;
    }

    @Override
    public void load() {

        Label title = new Label(CoreFont.load("hello.font.png"), "Loading...", 320, 240, 100,30);
        title.setAnchor(Sprite.CENTER);
        add(new FilledSprite(200,100,500,300, Colors.DARKGRAY));
        add(title);
    }

    boolean pop;

    @Override
    public void update(int elapsedTime) {
        if(download.getState() == Download.SUCCESS) {
            if(!pop) {
                System.out.println("success!");
                Timeline t = new Timeline();
                t.addEvent(new TimelineEvent(1000) {
                    public void run() {
                        Stage.popScene();
                    }
                });
                t.play();
                this.addTimeline(t);
                pop=true;
            }
        } else {
            System.out.println("download="+download.getPercentDownloaded());
        }
    }
}
